﻿var obj = {
    qualityinspectionId: '',
    qualityinspectionName: "",
    qualityinspectionBH: "",
    qualityinspectiontool: "",
    qualityinspectionmethood: "",
    qualityinspectionmetype: "",
    standardvalue: "",
    remark:"",
    createdBy: "",
    createdDate: "",
    updatedBy: "",
    updatedDate: "",
    deletedBy: "",
    deletedDate: "",
    isDeleted: "",
}
layui.use(['table', 'dropdown', 'layer', 'form'], function () {
    var table = layui.table;
    var dropdown = layui.dropdown;
    var layer = layui.layer;
    var form = layui.form;
    var laypage = layui.laypage;
  window.DeviceTan = function DeviceTan() {
        layer.open({
            type: 1, //page 层类型
            area: ['800px', '400px'],
            title: '新增质检项目',
            shade: 0.6, //遮罩透明度
            shadeClose: true, //点击遮罩区域，关闭弹层
            maxmin: true, //允许全屏最小化
            anim: 0, //0-6 的动画形式，- 1 不开启
            content: `
                 <div style="padding: 32px;">
                                           <form class="layui-form layui-form-pane" action="">
                                            <div class="layui-form-item">
                                             <div class="layui-inline" width=150>
                                                       <label class="layui-form-label">质检项目名称:</label>
                                               <div class="layui-input-block">
                                                         <input type="text" id="qualityinspectionName" lay-verify="required" placeholder="请输入" autocomplete="off"  class="layui-input">
                                                 </div>
                                             </div>
                                            
                                             <div class="layui-inline">
                                                       <label class="layui-form-label">质检项目编号:</label>
                                               <div class="layui-input-inline">
                                                        <input type="text" id="qualityinspectionBH" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input">
                                               </div>
                                             </div>
                                           </div>
                                           <div class="layui-inline">
                                                       <label class="layui-form-label">质检工具:</label>
                                               <div class="layui-input-inline">
                                                        <input type="text" id="qualityinspectiontool" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input">
                                               </div>
                                             </div>
                                 <div class="layui-inline">
                                                               <label class="layui-form-label">质检方法:</label>
                                                       <div class="layui-input-block">
                                                                         <select id="qualityinspectionmethood" name="deviceStatus" lay-filter="aihao">
                                                                           <option value="">请选择质检方法</option>
                                                             <option value="仪器测量">仪器测量</option>
                                                             <option value="目测量">目测量</option>
                                                             <option value="尺寸量">尺寸量</option>
                                                         </select>
                                                       </div>
                                                     </div>
                                <div class="layui-inline">
                                                               <label class="layui-form-label">质检类型:</label>
                                                       <div class="layui-input-block">
                                                                         <select id="qualityinspectionmetype" name="deviceStatus" lay-filter="aihao">
                                                                          <option value="">请选择质检类型</option>
                                                             <option value="数值">数值</option>
                                                      </select>
                                                       </div>
                                                     </div>
 
                                           <div class="layui-inline">
                                                                <label class="layui-form-label">标准值:</label>
                                                       <div class="layui-input-block">
                                                                         <select id="standardvalue" name="deviceStatus" lay-filter="aihao">
                                                                                 <option value="">请选择标准值</option>
                                                             <option value="外观完整">外观完整</option>
                                                              <option value="按图纸检测">按图纸检测</option>
                                                         </select>
                                                       </div>
                                                     </div>
                             
                                     <div class="layui-inline">
                                                       <label class="layui-form-label">备注:</label>
                                               <div class="layui-input-inline">
                                                          <input type="text" id="remark" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input" />

                                               </div>
                                             </div>
                                           </div>
                                   </div>
                                   <div class="layui-form-item">
                                             <button class="layui-btn" lay-submit lay-filter="demo2" onclick="DeviceAdd()">确认</button>
                                   
                                   </div>
                                 </form>
                                   </div>`
        });

        form.render()
    }
    window.DeviceAdd = function DeviceAdd() {
        qualityinspectionName = $("#qualityinspectionName").val()
        qualityinspectionBH = $("#qualityinspectionBH").val()
        qualityinspectiontool = $("#qualityinspectiontool").val()
        qualityinspectionmethood = $("#qualityinspectionmethood").val()
        qualityinspectionmetype = $("#qualityinspectionmetype").val()
        standardvalue = $("#standardvalue").val()
        remark = $("#remark").val()
     
        $.ajax({
            url: '../Quality/QualspectionAdd',
            type: 'post',
            data: {
                QualityinspectionName: qualityinspectionName,
                QualityinspectionBH: qualityinspectionBH,
                Qualityinspectiontool: qualityinspectiontool,
                Qualityinspectionmethood: qualityinspectionmethood,
                Qualityinspectionmetype: qualityinspectionmetype,
                Standardvalue: standardvalue,
                remark: remark,
              CreatedBy: "小明",
                DeletedBy: "",
                DeletedDate: "",
                IsDeleted: false,
                UpdatedBy: "",
                UpdatedDate: "",
                token: "",
            },
            //contentType: 'application/json',
            success: function (res) {
                console.log(res)
                var res = JSON.parse(res)
                if (res.data > 0) {
                    alert("添加成功")
                    window.location.href = '/Quality/QualityinspectionShow'
                }
                else {
                    alert("添加失败")
                }

            }
        })
    }
    // 点击导出按钮
    document.getElementById('exportBtn').addEventListener('click', function () {
        var checkStatus = table.checkStatus('carriertable');  // 获取当前表格的选中状态
        var selectedData = checkStatus.data;  // 获取选中的数据
        if (selectedData.length === 0) {
            alert('请先选择要导出的数据!');
            return;
        }

        // 使用 XLSX 导出选中的数据
        var wb = XLSX.utils.book_new();
        var ws = XLSX.utils.json_to_sheet(selectedData); // 将选中的数据转换为工作表
        XLSX.utils.book_append_sheet(wb, ws, 'Sheet1');

        // 导出为 Excel 文件
        XLSX.writeFile(wb, '质检组项目.xlsx');
    });



    $(function () {
        Show();
    });

    window.Show = function Show() {
        layui.use(function () {
    var QualityinspectionBH = $("#QualityinspectionBH").val();
            var CreatedDate = $("#CreatedDate").val();

            // 先进行表格的初始渲染
            table.render({
                elem: '#carriertable',  // 表格元素的选择器
                page: {
                    limit: 5,
                    limits: [5, 8, 10]
                },
                cols: [[
                    { type: 'checkbox', fixed: 'left' },
                    { field: 'qualityinspectionName', title: '质检项目名称' },
                    { field: 'qualityinspectionBH', title: '质检项目编号' },
                    { field: 'qualityinspectionmethood', title: '质检方法' },
                    { field: 'qualityinspectiontool', title: '质检工具' },
                    { field: 'qualityinspectionmetype', title: '质检类型' },
                    { field: 'standardvalue', title: '标准值' },
                    { field: 'createdDate', title: '创建时间' },
                    { field: 'createdBy', title: '创建人' },
                    { field: 'remark', title: '备注' },
                    {
                        field: '', width:260, title: '操作', templet: function (d) {
                            return '<a class="layui-btn layui-btn-edit layui-btn-xs" onclick="FanUpdate(' + d.qualityinspectionId + ')"><i class="layui-icon layui-icon-edit"></i>编辑</a> ' +
                                '<a class="layui-btn layui-btn-edit layui-btn-xs" onclick="Look(' + d.qualityinspectionId + ')"><i class="layui-icon layui-icon-edit"></i>查看</a> '+
                            '<a class="layui-btn layui-btn-danger layui-btn-xs" onclick="IsDel(' + d.qualityinspectionId + ')"><i class="layui-icon layui-icon-delete"></i>删除</a>';
                        }

                    }
                ]],
                // 初始时可以先不加载数据，等待 ajax 请求成功后再更新
                data: []
            });

            // 创建表格实例
            $.ajax({
                url: "../Quality/QualspectionShow",
                type: "get",
                data: {
                    pageindex: 1,
                    pagesize: 100,
                    token: "",
                    QualityinspectionBH: QualityinspectionBH,
                    CreatedDate: CreatedDate
                },

                success: function (data) {
                    data = JSON.parse(data);
                    console.log(data.data.list);
                    // 在 ajax 请求成功后，使用正确的表格 ID 进行 reload
                    table.reload('carriertable', {
                        page: {
                            limit: 5,
                            limits: [5, 8, 10]
                        },
                        data: data.data.list
                    });
                },
                error: function () {
                    console.log("请求失败");
                }
            });
        });
    }

    window.IsDel = function IsDel(qualityinspectionId) {
        console.log(qualityinspectionId)
        var token = localStorage.getItem("token")
        var model = JSON.stringify({
            QualityinspectionId: [qualityinspectionId],
            DeletedBy: "",
            DeletedDate: ""
            })
        console.log(model)
        layer.confirm("确认删除吗", function () {
            $.ajax({
                url: '../Quality/IsDelDoQpeion',
                data: { model: model, token: token },
                type: 'post',
                success: function (res) {
                    console.log(res);
                    var res = JSON.parse(res);
                    if (res.data > 0) {
                        layer.msg("删除成功", { icon: 1 });
                        Show();
                    } else {
                        layer.msg("删除失败", { icon: 2 });
                    }
                }
            });
        });
    }
   //反填查看
    window.Look = function Look(qualityinspectionId) {
        console.log(qualityinspectionId)
        $.ajax({
            url: '../Quality/QpeionFanDo',
            data: {
                QualityinspectionId: qualityinspectionId,
                token: ""
            },
            type: 'Get',
            success: function (res) {
            var res = JSON.parse(res)
                console.log(res)
                $.each(res, function () {
                    $("#qualityinspectionId").val(this.qualityinspectionId)
                    $("#qualityinspectionName").val(this.qualityinspectionName)
                    $("#qualityinspectionBH").val(this.qualityinspectionBH)
                    $("#qualityinspectiontool").val(this.qualityinspectiontool)
                    $("#qualityinspectionmethood").val(this.qualityinspectionmethood)
                    $("#qualityinspectionmetype").val(this.qualityinspectionmetype)
                    $("#standardvalue").val(this.standardvalue)
                    $("#createdBy").val(this.createdBy)
                    $("#createdDate").val(this.createdDate)
                  $("#updatedBy").val(this.updatedBy)
                    $("#updatedDate").val(this.updatedDate)
                    $("#deletedBy").val(this.deletedBy)
                    $("#deletedDate").val(this.deletedDate)
                    $("#isDeleted").val(this.isDeleted)
                     $("#remark").val(this.remark)
                 
         form.render(); // 重新渲染checkbox表单元素
                })
            }
        })
        layer.open({
            type: 1, //page 层类型
            area: ['800px', '400px'],
            title: '查看质检项目',
            shade: 0.6, //遮罩透明度
            shadeClose: true, //点击遮罩区域，关闭弹层
            maxmin: true, //允许全屏最小化
            anim: 0, //0-6 的动画形式，- 1 不开启
            content: `  <div style="padding: 32px;">
                                           <form class="layui-form layui-form-pane" action="">
                                            <div class="layui-form-item">
                                             <div class="layui-inline">
                                                       <label class="layui-form-label">质检项目名称:</label>
                                               <div class="layui-input-block">
                                                         <input type="text" id="qualityinspectionName" lay-verify="required" placeholder="请输入"      autocomplete="off"  class="layui-input">
                                                 </div>
                                             </div>
                                             <div class="layui-inline">
                                                       <label class="layui-form-label">质检项目编号:</label>
                                               <div class="layui-input-inline">
                                                        <input type="text" id="qualityinspectionBH" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input">
                                               </div>
                                             </div>
                                           </div>
                                           <div class="layui-inline">
                                                       <label class="layui-form-label">质检工具:</label>
                                               <div class="layui-input-inline">
                                                        <input type="text" id="qualityinspectiontool" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input">
                                               </div>
                                             </div>
                                 <div class="layui-inline">
                                                               <label class="layui-form-label">质检方法:</label>
                                                       <div class="layui-input-block">
                                                                         <select id="qualityinspectionmethood" name="deviceStatus" lay-filter="aihao">
                                                                           <option value="">请选择质检方法</option>
                                                             <option value="仪器测量">仪器测量</option>
                                                             <option value="目测量">目测量</option>
                                                             <option value="尺寸量">尺寸量</option>
                                                         </select>
                                                       </div>
                                                     </div>

                                         <div class="layui-inline">
                                                               <label class="layui-form-label">质检类型:</label>
                                                       <div class="layui-input-block">
                                                                         <select id="qualityinspectionmetype" name="deviceStatus" lay-filter="aihao">
                                                                          <option value="">请选择质检类型</option>
                                                             <option value="数值">数值</option>
                                                        
                                                         </select>
                                                       </div>
                                                     </div>
 
                                           <div class="layui-inline">
                                                                <label class="layui-form-label">标准值:</label>
                                                       <div class="layui-input-block">
                                                                         <select id="standardvalue" name="deviceStatus" lay-filter="aihao">
                                                                                 <option value="">请选择标准值</option>
                                                             <option value="外观完整">外观完整</option>
                                                              <option value="按图纸检测">按图纸检测</option>
                                                         </select>
                                                       </div>
                                                     </div>
                             
                                     <div class="layui-inline">
                                                       <label class="layui-form-label">备注:</label>
                                               <div class="layui-input-inline">
                                                          <input type="text" id="remark" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input" />

                                               </div>
                                             </div>
                                           </div>
                                   </div>
                                   <div class="layui-form-item">
                                             
                                   
                                   </div>
                                 </form>
                                   </div> `,
        });
        form.render()
     
    }
    //反填编辑
    window.FanUpdate = function FanUpdate(qualityinspectionId) {
        $.ajax({
            url: '../Quality/QpeionFanDo',
            data: {
                QualityinspectionId: qualityinspectionId,
                token: ""
            },
            type: 'Get',
            success: function (res) {

                var res = JSON.parse(res)
                console.log(res)
                $.each(res, function () {
                    $("#qualityinspectionId").val(this.qualityinspectionId)
                    $("#qualityinspectionName").val(this.qualityinspectionName)
                    $("#qualityinspectionBH").val(this.qualityinspectionBH)
                    $("#qualityinspectiontool").val(this.qualityinspectiontool)
                    $("#qualityinspectionmethood").val(this.qualityinspectionmethood)
                    $("#qualityinspectionmetype").val(this.qualityinspectionmetype)
                    $("#standardvalue").val(this.standardvalue)
                    $("#remark").val(this.remark)
                    obj.qualityinspectionId = this.qualityinspectionId,
                    obj.qualityinspectionName = this.qualityinspectionName,
                    obj.qualityinspectionBH = this.qualityinspectionBH,
                    obj.qualityinspectiontool = this.qualityinspectiontool,
                    obj.qualityinspectionmethood = this.qualityinspectionmethood,
                    obj.qualityinspectionmetype = this.qualityinspectionmetype,
                    obj.standardvalue = this.standardvalue,
                    obj.remark = this.remark,
                    obj.createdBy = this.createdBy,
                    obj.createdDate = this.createdDate,
                    obj.updatedBy = this.updatedBy,
                    obj.updatedDate = this.updatedDate,
                    obj.deletedBy = this.deletedBy,
                    obj.deletedDate = this.deletedDate,
                    obj.isDeleted = this.isDeleted,
                        form.render(); // 重新渲染checkbox表单元素
                })
            }
        })
        layer.open({
            type: 1, //page 层类型
            area: ['800px', '400px'],
            title: '修改质检组',
            shade: 0.6, //遮罩透明度
            shadeClose: true, //点击遮罩区域，关闭弹层
            maxmin: true, //允许全屏最小化
            anim: 0, //0-6 的动画形式，- 1 不开启
            content: `
                             <div style="padding: 32px;">
                                           <form class="layui-form layui-form-pane" action="">
                                            <div class="layui-form-item">
                                             <div class="layui-inline">
                                                       <label class="layui-form-label">质检项目名称:</label>
                                               <div class="layui-input-block">
                                                         <input type="text" id="qualityinspectionName" lay-verify="required" placeholder="请输入"      autocomplete="off"  class="layui-input">
                                                 </div>
                                             </div>
                                             <div class="layui-inline">
                                                       <label class="layui-form-label">质检项目编号:</label>
                                               <div class="layui-input-inline">
                                                        <input type="text" id="qualityinspectionBH" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input">
                                               </div>
                                             </div>
                                           </div>
                                           <div class="layui-inline">
                                                       <label class="layui-form-label">质检工具:</label>
                                               <div class="layui-input-inline">
                                                        <input type="text" id="qualityinspectiontool" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input">
                                               </div>
                                             </div>
                                 <div class="layui-inline">
                                                               <label class="layui-form-label">质检方法:</label>
                                                       <div class="layui-input-block">
                                                                         <select id="qualityinspectionmethood" name="deviceStatus" lay-filter="aihao">
                                                                           <option value="">请选择质检方法</option>
                                                             <option value="仪器测量">仪器测量</option>
                                                             <option value="目测量">目测量</option>
                                                             <option value="尺寸量">尺寸量</option>
                                                         </select>
                                                       </div>
                                                     </div>

                                         <div class="layui-inline">
                                                               <label class="layui-form-label">质检类型:</label>
                                                       <div class="layui-input-block">
                                                                         <select id="qualityinspectionmetype" name="deviceStatus" lay-filter="aihao">
                                                                          <option value="">请选择质检类型</option>
                                                             <option value="数值">数值</option>

                                                         </select>
                                                       </div>
                                                     </div>

                                           <div class="layui-inline">
                                                                <label class="layui-form-label">标准值:</label>
                                                       <div class="layui-input-block">
                                                                         <select id="standardvalue" name="deviceStatus" lay-filter="aihao">
                                                                                 <option value="">请选择标准值</option>
                                                             <option value="外观完整">外观完整</option>
                                                              <option value="按图纸检测">按图纸检测</option>
                                                         </select>
                                                       </div>
                                                     </div>

                                     <div class="layui-inline">
                                                       <label class="layui-form-label">备注:</label>
                                               <div class="layui-input-inline">
                                                          <input type="text" id="remark" lay-verify="required" placeholder="请输入"   autocomplete="off"  class="layui-input" />

                                               </div>
                                             </div>
                                           </div>
                                   </div>
                                   <div class="layui-form-item">
                                      <button class="layui-btn" lay-submit lay-filter="demo2" onclick="Update()">修改</button>

                                   </div>
                                 </form>
                                   </div> `,
        });
        form.render()
        window.Update = function Update() {
           qualityinspectionName =$("#qualityinspectionName").val()
            qualityinspectionBH =$("#qualityinspectionBH").val()
            qualityinspectiontool =$("#qualityinspectiontool").val()
            qualityinspectionmethood =$("#qualityinspectionmethood").val()
            qualityinspectionmetype =$("#qualityinspectionmetype").val()
            standardvalue =$("#standardvalue").val()
            remark =$("#remark").val()
              var obj1 = {
                  qualityinspectionId: '',
                  qualityinspectionName: "",
                  qualityinspectionBH: "",
                  qualityinspectiontool: "",
                  qualityinspectionmethood: "",
                  qualityinspectionmetype: "",
                  standardvalue: "",
                  remark: "",
                  createdBy: "",
                  createdDate: "",
                  updatedBy: "",
                  updatedDate: "",
                  deletedBy: "",
                  deletedDate: "",
                  isDeleted: "",
            }
            obj1.qualityinspectionId = obj.qualityinspectionId
            obj1.qualityinspectionName = qualityinspectionName
            obj1.qualityinspectionBH = qualityinspectionBH
            obj1.qualityinspectiontool = qualityinspectiontool
            obj1.qualityinspectionmethood = qualityinspectionmethood
            obj1.qualityinspectionmetype = qualityinspectionmetype
            obj1.standardvalue = standardvalue
            obj1.remark = remark
            obj1.createdBy = obj.createdBy
            obj1.createdDate = obj.createdDate
            obj1.updatedBy = obj.updatedBy
             obj1.updatedDate = obj.updatedDate
            obj1.deletedBy = obj.deletedBy
            obj1.deletedDate = obj.deletedDate
            obj1.isDeleted = obj.isDeleted
            console.log(obj1)
          
            var token = localStorage.getItem("token")
            $.ajax({
                url: '../Quality/QualityspectionupdateDo',
                type: 'post',
                data: { obj1: obj1, token: token },
                //contentType: 'application/json',
                success: function (res) {
                    console.log(res)
                    var res = JSON.parse(res)
                    if (res.data > 0) {
                        alert("修改成功")
                        window.location.href = '/Quality/QualityinspectionShow'
                    }
                    else {
                        alert("修改失败")
                    }

                }
            })
        }
    }

});
